package com.example.mapper;


import com.example.entity.BuyTicketsInfo;
import com.example.entity.TicketDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TicketMapper {

    /**
     * 添加ticket
     * @param ticketDto
     */
    @Insert("insert into game_ticket(game_id,ticket_money1,ticket_quantity1,ticket_money2,ticket_quantity2,ticket_money3,ticket_quantity3,ticket_createTime,ticket_closeTime)" +
             "values(#{gameId},#{ticketMoney1},#{ticketQuantity1},#{ticketMoney2},#{ticketQuantity2},#{ticketMoney3},#{ticketQuantity3},#{ticketCreateTime},#{ticketCloseTime})")
    void insert(TicketDto ticketDto);

    @Delete("delete from game_ticket where id=#{id}")
    void deleteById(Integer id);

    @Update("update game_ticket set game_id= #{gameId},ticket_money1= #{ticketMoney1},ticket_quantity1= #{ticketQuantity1},"+
             "ticket_money2= #{ticketMoney2},ticket_quantity2= #{ticketQuantity2},ticket_money3= #{ticketMoney3},ticket_quantity3= #{ticketQuantity3},"+
              "ticket_createTime= #{ticketCreateTime},ticket_closeTime= #{ticketCloseTime}"+
             "where id = #{id}")
    void updateById(TicketDto ticketDto);


    List<TicketDto> selectAll(String gameName, String gameType);

    @Insert("insert into buy_tickets_info(game_id,user_id,tickets1,tickets2,tickets3,total_cost,ticket_buyTime) "+
     "values(#{gameId},#{userId},#{tickets1},#{tickets2},#{tickets3},#{totalCost},#{ticketBuyTime})")
        void insertBuyTickets(BuyTicketsInfo buyTicketsInfo);

    @Update("update game_ticket set ticket_quantity1 = ticket_quantity1 - #{tickets1},ticket_quantity2= ticket_quantity2 - #{tickets2},ticket_quantity3= ticket_quantity3 - #{tickets3} "+
     " where game_id = #{gameId}")
    void updateTickets(BuyTicketsInfo buyTicketsInfo);

    @Select("select * from buy_tickets_info where  user_id = #{userId}")
    List<BuyTicketsInfo> selectPageTicketsByUserId(Integer userId);

    List<BuyTicketsInfo> selectPageTickets(String gameId, String userId);
}
